<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="船员姓名" prop="crewName">
        <el-input
          v-model="queryParams.crewName"
          placeholder="请输入船员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="船员状态" prop="crewStatus">
        <el-select v-model="queryParams.crewStatus" placeholder="请选择船员状态" clearable>
          <el-option
            v-for="dict in dict.type.resume_work_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="resumeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="船员姓名" align="center" prop="crewName" />
      <el-table-column label="船员状态" align="center" prop="crewStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.resume_work_status" :value="scope.row.crewStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="船员国家-地区" align="center" prop="crewLocation" />
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" >
        <template slot-scope="scope">
            <span v-if="scope.row.updateTime!= null">
              {{ parseTime(scope.row.updateTime ) }}
            </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:resume:detail']"
          >船员简历详情</el-button>
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:resume:remove']"
          >删除</el-button>-->
          <el-button
            v-if="scope.row.recommendType !== 1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="recommendation(scope.row)"
            v-hasPermi="['system:resume:recommendation']"
          >推荐</el-button>
          <el-button
            v-else
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="cancelRecommendationResume(scope.row)"
            v-hasPermi="['system:resume:recommendation']"
          >取消推荐</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改船员简历对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="船员姓名" prop="crewName">
          <el-input v-model="form.crewName" placeholder="请输入船员姓名" disabled/>
        </el-form-item>
        <el-form-item label="船员状态" prop="crewStatus" disabled>
          <el-radio-group v-model="form.crewStatus">
            <el-radio
              v-for="dict in dict.type.resume_work_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="船员国家-地区" prop="crewLocation">
          <el-input v-model="form.crewLocation" placeholder="请输入船员国家-地区" disabled/>
        </el-form-item>
        <el-form-item label="毕业院校" prop="graduateSchool">
          <el-input v-model="form.graduateSchool" placeholder="请输入毕业院校" disabled/>
        </el-form-item>
        <el-form-item label="工作经验" prop="crewWorkExperience">
          <el-input v-model="form.crewWorkExperience" placeholder="请输入工作经验" disabled/>
        </el-form-item>
        <el-form-item label="自我介绍" prop="crewSelfIntroduction">
          <el-input v-model="form.crewSelfIntroduction" type="textarea" placeholder="请输入内容" disabled/>
        </el-form-item>
        <el-form-item label="学习专业" prop="studyMajor">
          <el-input v-model="form.studyMajor" placeholder="请输入学习专业" disabled/>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthDate">
          <el-input v-model="form.birthDate" placeholder="请输入出生日期" disabled/>
        </el-form-item>
        <el-form-item label="现居地址" prop="currentAddress">
          <el-input v-model="form.currentAddress" placeholder="请输入现居地址" disabled/>
        </el-form-item>
        <el-form-item label="其他说明" prop="otherDescription">
          <el-input v-model="form.otherDescription" placeholder="请输入其他说明" disabled/>
        </el-form-item>
        <el-form-item label="专业技能" prop="professionalSkills">
          <el-input v-model="form.professionalSkills" placeholder="请输入专业技能" disabled/>
        </el-form-item>
<!--        <el-form-item label="头像图片" prop="headshotId">
          <el-input v-model="form.headshotId" placeholder="请输入头像图片" />
        </el-form-item>
        <el-form-item label="证书图片" prop="certificatesId">
          <el-input v-model="form.certificatesId" placeholder="请输入证书图片" />
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <div v-show="diaType !== 'detail'">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listResume, getResume, delResume, addResume, updateResume, recommendationResume, cancelRecommendationResume } from "@/api/system/crewResume";

export default {
  name: "Resume",
  dicts: ['resume_work_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 船员简历表格数据
      resumeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        crewName: null,
        crewStatus: null,
        crewLocation: null,
        graduateSchool: null,
        crewWorkExperience: null,
        crewSelfIntroduction: null,
        studyMajor: null,
        birthDate: null,
        currentAddress: null,
        otherDescription: null,
        professionalSkills: null,
        headshotId: null,
        certificatesId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      diaType: ''
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询船员简历列表 */
    getList() {
      this.loading = true;
      listResume(this.queryParams).then(response => {
        this.resumeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        crewName: null,
        crewStatus: null,
        crewLocation: null,
        graduateSchool: null,
        crewWorkExperience: null,
        crewSelfIntroduction: null,
        studyMajor: null,
        birthDate: null,
        currentAddress: null,
        otherDescription: null,
        professionalSkills: null,
        headshotId: null,
        certificatesId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams=this.resetForm(this.queryParams);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.diaType = 'add'
      this.open = true;
      this.title = "添加船员简历";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.diaType = 'edit'
      const id = row.id || this.ids
      getResume(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "船员简历详情";
      });
    },
    /** 详情按钮 */
    handleDetail(row) {
      this.reset();
      this.diaType = 'detail'
      const id = row.id || this.ids
      getResume(id).then(response => {
        this.form = response.data;
        this.form.birthDate = new Date(parseInt(this.form.birthDate) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ')
        this.open = true;
        this.title = "船员简历详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateResume(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addResume(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除？').then(function() {
        return delResume(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/crewResume/export', {
        ...this.queryParams
      }, `resume_${new Date().getTime()}.xlsx`)
    },
    /** 推荐 */
    recommendation(row) {
      const id = row.id
      recommendationResume(id).then(response => {
        this.getList();
      });
    },
    /** 取消推荐 */
    cancelRecommendationResume(row) {
      const id = row.id
      cancelRecommendationResume(id).then(response => {
        this.getList();
      });
    }
  }
};
</script>
